Filter hook 'rest_{$this->post_type}_trashable'

in WP Core File wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php at line 1109

View Source

rest_{$this->post_type}_trashable

Filter Hook
Description
Filters whether a post is trashable. The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. Possible hook names include: - `rest_post_trashable` - `rest_page_trashable` - `rest_attachment_trashable` Pass false to disable Trash support for the post.

Hook Information

File Location wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php View on GitHub
Hook Type Filter
Line Number 1109

Hook Parameters

Type Name Description
bool $supports_trash Whether the post type support trashing.
WP_Post $post The Post object being considered for trashing support.

Usage Examples

Basic Usage
<?php
// Hook into rest_{$this->post_type}_trashable
add_filter('rest_{$this->post_type}_trashable', 'my_custom_filter', 10, 2);

function my_custom_filter($supports_trash, $post) {
    // Your custom filtering logic here
    return $supports_trash;
}

Source Code Context

wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:1109 - How this hook is used in WordPress core
<?php
1104  		 * @since 4.7.0
1105  		 *
1106  		 * @param bool    $supports_trash Whether the post type support trashing.
1107  		 * @param WP_Post $post           The Post object being considered for trashing support.
1108  		 */
1109  		$supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post );
1110  
1111  		if ( ! $this->check_delete_permission( $post ) ) {
1112  			return new WP_Error(
1113  				'rest_user_cannot_delete_post',
1114  				__( 'Sorry, you are not allowed to delete this post.' ),

PHP Documentation

<?php
/**
		 * Filters whether a post is trashable.
		 *
		 * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
		 *
		 * Possible hook names include:
		 *
		 *  - `rest_post_trashable`
		 *  - `rest_page_trashable`
		 *  - `rest_attachment_trashable`
		 *
		 * Pass false to disable Trash support for the post.
		 *
		 * @since 4.7.0
		 *
		 * @param bool    $supports_trash Whether the post type support trashing.
		 * @param WP_Post $post           The Post object being considered for trashing support.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
Related Hooks

Related hooks will be displayed here in future updates.